package com.hzit.controller;

import com.hzit.entity.Student;
import com.hzit.service.StudentService;
import com.hzit.util.PageResult;
import com.hzit.util.R;
import com.hzit.vo.StudentVO;
import jdk.nashorn.internal.objects.annotations.Getter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 类名：
 * 作者：WF
 * 功能：
 */
// @Controller
// @ResponseBody
@RestController
@RequestMapping("/student")
public class StudentController {

	@Autowired
	private StudentService studentService;

	// 1. 列表学生
	@GetMapping("/list")
	public R list(){
		List<Student> list = studentService.findAll();
		return R.ok().data("list",list);
	}

	// 2. 分页查询
	// http://localhost:9000/findByPage.do/1/5
	@GetMapping("/findByPage/{page}/{pageSize}")
	public R findByPage(@PathVariable Integer page,
	                    @PathVariable("pageSize") Integer pageSize){
		PageResult<Student> pageResult = studentService.findByPage(page,pageSize);
		return R.ok().data("pageResult",pageResult);
	}

	// 3. 分页带条件查询
	// http://localhost:9000/findByPage/1/5
	@PostMapping("/search/{page}/{pageSize}")
	public R search(@PathVariable("page") Integer page,
	                @PathVariable("pageSize") Integer pageSize,
	                @RequestBody(required = false) StudentVO vo){
		PageResult<Student> pageResult = studentService.search(page,pageSize,vo);
		return R.ok().data("pageResult",pageResult);
	}
}
